﻿#region imports

using System;
using System.Web;

#endregion

namespace Codeplex.ODataTFS.Web.Infrastructure
{
	public static class HttpRequestExtensions
	{
		//TOOD: Investigate
		public static bool IsRootCollectionListRequest(this HttpRequest request, int segmentCount)
		{
			var path = request.Path;
			if (!request.ApplicationPath.Equals("/", StringComparison.OrdinalIgnoreCase))
			{
				path = path.Replace(request.ApplicationPath, string.Empty).Replace("//", "/");
			}

			if (string.IsNullOrEmpty(path) || path.Equals("/"))
			{
				return true;
			}

			return path.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries).Length == segmentCount;
		}
	}
}
